#![feature(exclusive_range_pattern)]
use rand::{thread_rng, Rng};

fn main() {
    // let prizes = vec!["一等奖", "二等奖", "三等奖", "四等奖", "五等奖"];
    // let weights = vec![2, 5, 10, 33, 51];
    let prizes = ["一等奖", "二等奖", "三等奖", "四等奖", "五等奖"];
    let weights = [2, 5, 10, 33, 51];

    let sum: i32 = weights.iter().sum();

    // 权重随机区间
    let mut random_range: Vec<i32> = Vec::new(); // 动态数组
    let mut temp = 0;
    for i in weights.into_iter() {
        random_range.push(temp + i);
        temp += i;
    }

    let random_number: i32 = thread_rng().gen_range(0, sum);
    println!("{}", random_number);
    println!("{:?}", random_range[1]);
   // if let Some(a) = random_range.into_iter().nth(0);

    match random_number {
        0..weights[0] => println!("{}", prizes[0]),
        // 0 => println!("{}", prizes[1]),
        // 0 => println!("{}", prizes[2]),
        // 0 => println!("{}", prizes[3]),
        // 0 => println!("{}", prizes[4]),
        _ => println!("毛都没有"),
    }
}
